use super::Department;
use sea_orm_migration::prelude::*;

/// 岗位表
#[derive(Iden)]
pub enum Position {
    Table,

    /// 岗位编号
    Id,

    /// 名称
    Name,

    /// 所属部门
    DepartmentId,

    /// 类型：管理 | 技术 | 营销 | 市场
    Kind,

    /// 岗位编制
    ManningQuotas,
}

impl Position {
    pub fn table() -> TableCreateStatement {
        Table::create()
            .table(Self::Table)
            .if_not_exists()
            .col(
                ColumnDef::new(Self::Id)
                    .integer()
                    .primary_key()
                    .auto_increment(),
            )
            .col(ColumnDef::new(Self::Name).string().unique_key().not_null())
            .col(ColumnDef::new(Self::DepartmentId).integer().not_null())
            .col(ColumnDef::new(Self::Kind).char_len(2).not_null())
            .col(ColumnDef::new(Self::ManningQuotas).integer())
            .to_owned()
    }

    pub fn under_department() -> ForeignKeyCreateStatement {
        ForeignKey::create()
            .name("FK_position_department")
            .from(Self::Table, Self::DepartmentId)
            .to(Department::Table, Department::Id)
            .to_owned()
    }

    pub fn drop() -> TableDropStatement {
        Table::drop().table(Self::Table).to_owned()
    }
}
